// 处理推荐作者
const db =require("../lib/db")
const { user } = require("../lib/db.config")

function author(){
    return new Promise((resolve,reject)=>{
        let sql = "select * from author"
        db.querySql(sql).then(data=>{
            // console.log(data)
            if(data.length == 0){
                resolve(404)
                // console.log(data)
            }else{
            //    做一个乱序处理
            let arr =data.sort(()=>0.5 -Math.random())
            // console.log(arr)
            let arr2 =[]
            arr.map(element=>{
                arr2.push({
                    _id : Buffer.from(String(element._id)).toString("base64"),
                    userName : element.userName,
                    headimg : element.headimg,
                    descs : element.descs
                })
            })
            console.log(arr2)
            resolve(arr2)
            }
        })  
    
    }
)}

module.exports = author
